/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package eypweb_bsc;

import java.io.File;
import java.net.URL;
import java.sql.*;
import java.util.ArrayList;
import java.util.ResourceBundle;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventType;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextField;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

/**
 *
 * @author Kohalmi Istvan
 */

// muveleteket rogzito kepernyot megvalosito osztaly
public class OperationRegistry implements Initializable {

    @FXML
    private Button btnPreview;
    @FXML
    private Label errorLabel;
    @FXML
    private Label lBase;
    @FXML
    private Label lName;
    @FXML
    private Label lCurrency;
    @FXML
    private Label lDenomination;
    @FXML
    private Label lCommissionRateDelta;
    @FXML
    private Label lPriceRateDelta;
    @FXML
    private ChoiceBox cbType;
    @FXML
    private ChoiceBox cbPortfolio;
    @FXML
    private TextField tfCommissionHUF;
    @FXML
    private TextField tfGrossPrice;
    @FXML
    private TextField tfSerial;
    @FXML
    private TextField tfISIN;
    @FXML
    private TextField tfQuantity;
    @FXML
    private TextField tfNominal;
    @FXML
    private TextField tfNetRatePercent;
    @FXML
    private TextField tfNetRateValue;
    @FXML
    private TextField tfNetRateCurrency;
    @FXML
    private TextField tfAccumulatedInterestPercent;
    @FXML
    private TextField tfAccumulatedInterest;
    @FXML
    private TextField tfDividend;
    @FXML
    private TextField tfYieldPercent;
    @FXML
    private TextField tfYield;
    @FXML
    private TextField tfGrossPriceCurrency;
    @FXML
    private TextField tfBindingDate;
    @FXML
    private TextField tfBindingRateCurrency;
    @FXML
    private TextField tfFulfillmentDate;
    @FXML
    private TextField tfFulfillmentRateCurrency;
    @FXML
    private TextField tfExecutionDate;
    @FXML
    private TextField tfExecutionRateCurrency;
    @FXML
    private TextField tfComment;
    @FXML
    private TextField tfCommissionCurrency;
    @FXML
    private TextField tfCapitalValue;
    // megjelenitendo tablazat
    @FXML
    private TableView<Inventory> tblOperation;
    // munkatabla
    @FXML
    private TableView<Inventory> tblWork = new TableView<Inventory>();
    // aktiv ertekpapir
    private Isin isin;
    // aktiv muvelet
    private Operation operation;
    // azonositokat tarolo listak
    private ArrayList<Integer> portIds;
    private ArrayList<Integer> typeIds;

    // peldanyositaskor letrejon a ket lista
    public OperationRegistry() {
        portIds = new ArrayList<Integer>();
        typeIds = new ArrayList<Integer>();
    }

    // rogzites gombra kattintva
    @FXML
    private void handleRecordButtonAction(ActionEvent event) {
        errorLabel.setText("");
        // szamitasok elvegzese
        // ha elotte a felhasznalo mar megtette, akkor nem fog ujra szamolni
        handlePreviewButtonAction(new ActionEvent());
        if (!errorLabel.getText().isEmpty()) {
            return;
        }
        // ha nem volt kivetel megkezdodhet a tranzakcio rogzitese
        errorLabel.setText("A számítás sikeres. Tranzakció rögzítése folyamatban...");
        registerTransaction(operation, tblWork.getItems());
        // feluleti elemek tisztitasa
        errorLabel.setText("");
        lBase.setText("");
        lName.setText("");
        lCurrency.setText("");
        lDenomination.setText("");
        lCommissionRateDelta.setText("");
        lPriceRateDelta.setText("");
        tfCommissionHUF.setText("");
        tfSerial.setText("");
        tfGrossPrice.setText("");
        tfISIN.setText("");
        tfQuantity.setText("");
        tfNominal.setText("");
        tfNetRatePercent.setText("");
        tfNetRateValue.setText("");
        tfNetRateCurrency.setText("");
        tfAccumulatedInterestPercent.setText("");
        tfAccumulatedInterest.setText("");
        tfYieldPercent.setText("");
        tfYield.setText("");
        tfGrossPriceCurrency.setText("");
        tfBindingDate.setText("");
        tfBindingRateCurrency.setText("");
        tfFulfillmentDate.setText("");
        tfFulfillmentRateCurrency.setText("");
        tfExecutionDate.setText("");
        tfExecutionRateCurrency.setText("");
        tfComment.setText("");
        tfCommissionCurrency.setText("");
        tfCapitalValue.setText("");
        // szamitas gomb korlatozasa
        btnPreview.setDisable(true);
        isin=null;
    }

    // exportalas CSV-be
    @FXML
    private void handleCSVButtonAction(ActionEvent event) {
        CSVHandler.exportOperation(tblOperation.getItems());
    }

    // exportalas XLS-be
    @FXML
    private void handleXLSButtonAction(ActionEvent event) {
        XLSHandler.exportOperation(tblOperation.getItems());
    }

    // exportalas XML-be
    @FXML
    private void handleXMLButtonAction(ActionEvent event) {
        XMLHandler.exportOperation(tblOperation.getItems());
    }

    // relevans ISIN leltar betoltese
    @FXML
    private void handleISINButtonAction(ActionEvent event) {
        if (tfISIN.getText().isEmpty()) {
            errorLabel.setText("Az ISIN mező kitöltése kötelező!");
            return;
        }
        // ISIN mezo alapjan aktualis ertekpapir lekerdezese
        isin = Isin.getCurrentIsin(tfISIN.getText());
        // ISIN specifikus beviteli mezok beallitasa
        lName.setText(isin.getName());
        lDenomination.setText(Float.toString(isin.getDenomination()));
        lCurrency.setText(isin.getDeviza().getName());
        lBase.setText(isin.getBase());
        if (lCurrency.getText().equals("HUF")) {
            tfBindingRateCurrency.setText("1.0");
            tfFulfillmentRateCurrency.setText("1.0");
            tfExecutionRateCurrency.setText("1.0");
        }
        int port_id;
        Director director = Director.getInstance();
        AccessInfo ai = director.getAccessInfo();
        // tablazat torlese
        tblOperation.getItems().clear();
        try {
            // kapcsolodas
            Connection con = DriverManager.getConnection("jdbc:sqlserver://" + ai.getIPAddress() + ":" + ai.getPort() + ";databaseName=" + ai.getDBName(), ai.getUser(), ai.getPass());
            // adott parameterek szerinti leltarban levo elemek lekerdezese
            PreparedStatement inventoryStmt = con.prepareStatement("SELECT * FROM leltar "
                    + "WHERE id_isin = ? "
                    + "AND id_port = ? "
                    + "AND id_vk = ?  "
                    + "AND mennyiseg > 0 "
                    + "AND id IN (SELECT MAX(id) FROM leltar "
                    + "WHERE id_isin = ? "
                    + "AND id_port = ? "
                    + "AND id_vk = ? "
                    + "GROUP BY id_vetel) "
                    + "ORDER BY beszerzes_datum, id_vetel");

            // parameter atadas
            inventoryStmt.setInt(1, isin.getId());
            inventoryStmt.setInt(2, portIds.get(cbPortfolio.getSelectionModel().getSelectedIndex()));
            inventoryStmt.setInt(3, ai.getTrusteeSign());
            inventoryStmt.setInt(4, isin.getId());
            inventoryStmt.setInt(5, portIds.get(cbPortfolio.getSelectionModel().getSelectedIndex()));
            inventoryStmt.setInt(6, ai.getTrusteeSign());
            // lekerdezes eredmenye
            ResultSet inventoryRS = inventoryStmt.executeQuery();
            // amig van benne elem
            while (inventoryRS.next()) {
                // uj leltar objektum letrehozasa es feltoltese
                Inventory inv = new Inventory();
                inv.setAcquisitionDate(inventoryRS.getDate(6).toString());
                inv.setAcquisitionValue(inventoryRS.getLong(9));
                inv.setDerecogniseCurrencyRateDelta(inventoryRS.getLong(14));
                inv.setDerecogniseDividend(inventoryRS.getLong(12));
                inv.setDerecogniseInterest(inventoryRS.getLong(11));
                inv.setDerecogniseRateDelta(inventoryRS.getLong(13));
                inv.setMarketValue(inventoryRS.getLong(10));
                inv.setNominal(inventoryRS.getDouble(8));
                inv.setPurchaseId(inventoryRS.getNString(2));
                inv.setQuantity(inventoryRS.getInt(7));
                inv.setAcquisitionValueCurrency(inventoryRS.getDouble(15));
                inv.setAcquisitionRateCurrency(inventoryRS.getFloat(16));
                inv.setSerial(inventoryRS.getNString(17));
                // tablazat elemeinek bovitese
                tblOperation.getItems().add(inv);
            }
            btnPreview.setDisable(false);
            // kapcsolat lezarasa
            con.close();
        } catch (SQLException sqle) {
            errorLabel.setText(sqle.getMessage());
        }
    }

    // a Szamitas gomb megnyomasakor
    @FXML
    private void handlePreviewButtonAction(ActionEvent event) {
        // ha korabban mar megnyomtuk es a Rogzites gomb keri
        // az ujraszamitast, visszaterunk
        if (btnPreview.isDisable()) {
            return;
        }
        if (tfSerial.getText().isEmpty()) {
            errorLabel.setText("A műveleti azonosítót kötelező kitölteni!");
            return;
        }
        // datumformazas megkiserlese
        try {
            tfBindingDate.setText(tfBindingDate.getText().replace('.', '-'));
            Date.valueOf(tfBindingDate.getText());
            tfFulfillmentDate.setText(tfFulfillmentDate.getText().replace('.', '-'));
            Date.valueOf(tfFulfillmentDate.getText());
            tfExecutionDate.setText(tfExecutionDate.getText().replace('.', '-'));
            Date.valueOf(tfExecutionDate.getText());
        } catch (Exception e) {
            errorLabel.setText("Dátumformátum nem egyeztethető");
            return;
        }

        Director director = Director.getInstance();
        AccessInfo ai = director.getAccessInfo();
        if (isin == null) {
            errorLabel.setText("A számításhoz kötelező megadnia egy értékpapírt!");
            return;
        }
        // lebegopontos szamok formazasanak megkiserlese
        tfCommissionHUF.setText(tfCommissionHUF.getText().replace(',', '.'));
        tfGrossPrice.setText(tfGrossPrice.getText().replace(',', '.'));
        tfQuantity.setText(tfQuantity.getText().replace(',', '.'));
        tfNominal.setText(tfNominal.getText().replace(',', '.'));
        tfNetRatePercent.setText(tfNetRatePercent.getText().replace(',', '.'));
        tfNetRateValue.setText(tfNetRateValue.getText().replace(',', '.'));
        tfNetRateCurrency.setText(tfNetRateCurrency.getText().replace(',', '.'));
        tfAccumulatedInterestPercent.setText(tfAccumulatedInterestPercent.getText().replace(',', '.'));
        tfAccumulatedInterest.setText(tfAccumulatedInterest.getText().replace(',', '.'));
        tfYieldPercent.setText(tfYieldPercent.getText().replace(',', '.'));
        tfYield.setText(tfYield.getText().replace(',', '.'));
        tfGrossPriceCurrency.setText(tfGrossPriceCurrency.getText().replace(',', '.'));
        tfBindingRateCurrency.setText(tfBindingRateCurrency.getText().replace(',', '.'));
        tfFulfillmentRateCurrency.setText(tfFulfillmentRateCurrency.getText().replace(',', '.'));
        tfExecutionRateCurrency.setText(tfExecutionRateCurrency.getText().replace(',', '.'));
        tfCommissionCurrency.setText(tfCommissionCurrency.getText().replace(',', '.'));
        tfCapitalValue.setText(tfCapitalValue.getText().replace(',', '.'));
        
        // uj muvelet letrehozasa
        operation = new Operation();
        // muvelet ertekeinek feltoltese
        // operation.setAccountedCommissionRateDelta(lCommissionRateDelta.getText() == null?null:Long.valueOf(lCommissionRateDelta.getText()));
        // operation.setAccountedPriceRateDelta(lPriceRateDelta.getText() == null?null:Long.valueOf(lPriceRateDelta.getText()));
        operation.setAccumulatedInterest(Long.parseLong(tfAccumulatedInterest.getText()));
        operation.setAccumulatedInterestPercent(Float.parseFloat(tfAccumulatedInterestPercent.getText()));
        operation.setBindingDate(Date.valueOf(tfBindingDate.getText()));
        operation.setFulfillmentDate(Date.valueOf(tfFulfillmentDate.getText()));
        operation.setExecutionDate(Date.valueOf(tfExecutionDate.getText()));
        operation.setBindingRate(Float.parseFloat(tfBindingRateCurrency.getText()));
        operation.setFulfillmentRate(Float.parseFloat(tfFulfillmentRateCurrency.getText()));
        operation.setExecutionRate(Float.parseFloat(tfExecutionRateCurrency.getText()));
        operation.setCapitalValue(Long.parseLong(tfCapitalValue.getText()));
        operation.setCommissionHUF(Long.parseLong(tfCommissionHUF.getText()));
        operation.setCommissionCurrency(Double.parseDouble(tfCommissionCurrency.getText()));
        operation.setCurrencyRate(Double.parseDouble(tfNetRateCurrency.getText()));
        operation.setDividend(Long.parseLong(tfDividend.getText()));
        operation.setGrossPrice(Long.parseLong(tfGrossPrice.getText()));
        operation.setGrossPriceCurrency(Double.parseDouble(tfGrossPriceCurrency.getText()));
        operation.setIsin(isin);
        operation.setNetRatePercent(Float.parseFloat(tfNetRatePercent.getText()));
        operation.setNetRateValue(Long.parseLong(tfNetRateValue.getText()));
        operation.setNote(tfComment.getText());
        operation.setNominal(Double.parseDouble(tfNominal.getText()));
        operation.setOperationId(tfSerial.getText());
        operation.setPort(cbPortfolio.getSelectionModel().getSelectedItem().toString());
        operation.setQuantity(Integer.parseInt(tfQuantity.getText()));
        operation.setType(cbType.getSelectionModel().getSelectedItem().toString());
        operation.setYield(Long.parseLong(tfYield.getText()));
        operation.setYieldPercent(Float.parseFloat(tfYieldPercent.getText()));
        // munkatabla tisztitasa
        tblWork.getItems().clear();
        // tranzakciotipustol fuggo megvalositas
        String operationType = cbType.getSelectionModel().getSelectedItem().toString();
        if (operationType.equals("vásárlás")) {
            
            if (tfAccumulatedInterest.getText().isEmpty()) {
                tfAccumulatedInterest.setText("0");
            }
            if (tfAccumulatedInterestPercent.getText().isEmpty()) {
                tfAccumulatedInterestPercent.setText("0");
            }
            // vasarlas eseten csak egy uj elem van
            Inventory inv = new Inventory();
            inv.setAcquisitionDate(operation.getExecutionDate().toString());
            inv.setAcquisitionValue(new Long(operation.getNetRateValue()));
            inv.setDerecogniseCurrencyRateDelta(new Long(0));
            inv.setDerecogniseDividend(new Long(0));
            inv.setDerecogniseInterest(new Long(0));
            inv.setDerecogniseRateDelta(new Long(0));
            inv.setMarketValue(new Long(operation.getGrossPrice()));
            inv.setNominal(new Double(operation.getNominal()));
            inv.setPurchaseId(operation.getOperationId());
            inv.setQuantity(new Integer(operation.getQuantity()));
            inv.setAccumulatedInterestAccountedPrice(new Long(operation.getAccumulatedInterest()));
            inv.setDerecognisedCurrencyRateDelta(new Long(0));
            inv.setDerecognisedDividend(new Long(0));
            inv.setDerecognisedInterest(new Long(0));
            inv.setDerecognisedRateDelta(new Long(0));
            inv.setRealisedCurrencyRateDelta(new Long(0));
            inv.setRealisedDividend(new Long(0));
            inv.setRealisedInterest(new Long(0));
            inv.setRealisedRateDelta(new Long(0));
            inv.setSerial(operation.getOperationId());
            // elszamolas alapja ketfele lehet
            if (lBase.getText().equals("mennyiség"))
                inv.setAccountedBase(new Double(operation.getQuantity()));
            else
                inv.setAccountedBase(new Double(operation.getNominal()));
            inv.setAccountedValue(new Long(operation.getNetRateValue()));
            inv.setAcquisitionRateCurrency(new Float(operation.getFulfillmentRate()));
            inv.setAcquisitionValueCurrency(new Double(operation.getCurrencyRate()));

            tblWork.getItems().add(inv);

        }
        // eladas es lejarat ugyanugy kezelendo
        else if (operationType.equals("eladás")
                || operationType.equals("lejárat")) {
            // ha nincs a leltarban ilyen elem
            if (tblOperation.getItems().size() == 0) {
                errorLabel.setText("Nincs elég értékpapír az eladáshoz!");
                return;
            }
            // 
            if (tfQuantity.getText().isEmpty()) {
                errorLabel.setText("A mennyiséget kötelező megadni!");
                return;
            }
            // a tranzakcio teljes mennyisege
            int db_delta = Integer.parseInt(tfQuantity.getText());
            // a tranzakcio maradek mennyisege
            int db_marad = db_delta;
            int leltar = 0;
            for (Inventory oi : tblOperation.getItems()) {
                leltar += oi.getQuantity().intValue();
            }
            // ha tul keves ertekpapir van a leltarban
            if (leltar < db_delta) {
                errorLabel.setText("Nincs elég értékpapír az eladáshoz!");
                return;
            }
            int i = 0;
            // amig van meg a tranzakcio teljes mennyisegebol
            while (db_marad > 0) {
                Inventory cur = tblOperation.getItems().get(i);
                Inventory inv = new Inventory();
                // az aktualis befektetes mennyisege
                int db_bef = cur.getQuantity().intValue();
                // a maradek es befektetes darabszamabol a kisebbel dolgozunk
                int db_share = Math.min(db_marad, db_bef);
                inv.setAcquisitionDate(cur.getAcquisitionDate());
                inv.setAcquisitionValue(Math.round(cur.getAcquisitionValue()*(1.0-(double)db_share / db_bef)));
                inv.setAcquisitionRateCurrency(cur.getAcquisitionRateCurrency());
                inv.setAcquisitionValueCurrency(cur.getAcquisitionValueCurrency()*(1.0-(double)db_share / db_bef));
                inv.setMarketValue(Math.round(cur.getMarketValue() * (1.0 - (float)db_share / db_bef)));
                inv.setNominal(cur.getNominal() * (1.0 - (double)db_share / db_bef));
                if (lBase.getText().equals("névérték"))
                {
                    inv.setNominal(new Double(Math.round(inv.getNominal())));
                }
                inv.setPurchaseId(cur.getPurchaseId());
                inv.setQuantity(cur.getQuantity() - new Integer(db_share));
                inv.setAccumulatedInterestAccountedPrice(new Long(0));
                inv.setDerecogniseCurrencyRateDelta(cur.getDerecogniseCurrencyRateDelta());
                inv.setDerecogniseDividend(cur.getDerecogniseDividend());
                inv.setDerecogniseInterest(cur.getDerecogniseInterest());
                inv.setDerecogniseRateDelta(cur.getDerecogniseRateDelta());
                inv.setDerecognisedCurrencyRateDelta(Math.round(inv.getDerecogniseCurrencyRateDelta().doubleValue() * db_share / db_bef));
                inv.setDerecognisedDividend(Math.round(inv.getDerecogniseDividend().doubleValue() * db_share / db_bef));
                inv.setDerecognisedInterest(Math.round(inv.getDerecogniseInterest().doubleValue() * db_share / db_bef));
                inv.setDerecognisedRateDelta(Math.round(inv.getDerecogniseRateDelta().doubleValue() * db_share / db_bef));
                inv.setDerecogniseCurrencyRateDelta(cur.getDerecogniseCurrencyRateDelta() - inv.getDerecognisedCurrencyRateDelta());
                inv.setDerecogniseDividend(cur.getDerecogniseDividend() - inv.getDerecognisedDividend());
                inv.setDerecogniseInterest(cur.getDerecogniseInterest() - inv.getDerecognisedInterest());
                inv.setDerecogniseRateDelta(cur.getDerecogniseRateDelta() - inv.getDerecognisedRateDelta());
                inv.setRealisedCurrencyRateDelta((Math.round((double) db_share * ((Float.parseFloat(tfFulfillmentRateCurrency.getText()) - cur.getAcquisitionRateCurrency().floatValue())/ isin.getDeviza().getUnit()))));
                inv.setRealisedDividend((Math.round((double) db_share / db_delta * Long.parseLong(tfDividend.getText()))));
                inv.setRealisedInterest((Math.round((double) db_share / db_delta * Long.parseLong(tfAccumulatedInterest.getText()))));
                inv.setRealisedRateDelta((Math.round((double) db_share / db_delta * (Long.parseLong(tfNetRateValue.getText())) - cur.getAcquisitionValue().doubleValue() * db_share / db_bef - cur.getRealisedCurrencyRateDelta())));
                inv.setSerial(tfSerial.getText());
                if (lBase.getText().equals("mennyiség")) {
                    inv.setAccountedBase(new Double(db_share));
                } else {
                    inv.setAccountedBase((double) db_share / db_delta * Long.parseLong(tfNominal.getText()));
                }
                inv.setAccountedValue(Math.round(inv.getAcquisitionValue() * (double) db_share / db_bef));
                // a munkatabla elemeit bovitjuk
                tblWork.getItems().add(inv);
                // a maradekot csokkentjuk
                db_marad -= db_share;
                i++;
            }
        } else if (operationType.equals("kamatfizetés")) {
            if (tfAccumulatedInterest.getText().isEmpty()) {
                errorLabel.setText("A kamatfizetés mértékét kötelező megadni!");
                return;
            }
            if (tfNominal.getText().isEmpty()) {
                errorLabel.setText("A kamatfizetés névértékét kötelező megadni!");
                return;
            }
            long ne_delta = Long.parseLong(tfNominal.getText());
            long ne_marad = ne_delta;
            int i = 0;
            while (ne_marad > 0) {
                // rendkivul alacsony valoszinusegu eset kezelese
                // kamatfizetes olyan papirra ami mar nincs bent a leltarban
                if (i == tblOperation.getItems().size()) {
                    Inventory inv = new Inventory();

                    inv.setAcquisitionDate(null);
                    inv.setAcquisitionValue(new Long(0));
                    inv.setAcquisitionRateCurrency(new Float(0));
                    inv.setAcquisitionValueCurrency(new Double(0));
                    inv.setMarketValue(new Long(0));
                    inv.setNominal(new Double(ne_marad));
                    inv.setPurchaseId(null);
                    inv.setQuantity(new Integer(0));
                    inv.setAccumulatedInterestAccountedPrice(new Long(0));
                    inv.setDerecognisedCurrencyRateDelta(new Long(0));
                    inv.setDerecognisedDividend(new Long(0));
                    inv.setDerecognisedInterest(new Long(0));
                    inv.setDerecognisedRateDelta(new Long(0));
                    inv.setDerecogniseCurrencyRateDelta(new Long(0));
                    inv.setDerecogniseDividend(new Long(0));
                    inv.setDerecogniseInterest(new Long(0));
                    inv.setDerecogniseRateDelta(new Long(0));
                    inv.setRealisedCurrencyRateDelta(new Long(0));
                    inv.setRealisedDividend(new Long(0));
                    inv.setRealisedInterest(Math.round((double) ne_marad / ne_delta * Long.parseLong(tfAccumulatedInterest.getText())));
                    inv.setRealisedRateDelta(new Long(0));
                    inv.setSerial(tfSerial.getText());
                    inv.setAccountedBase((double) ne_marad / ne_delta * Long.parseLong(tfNominal.getText()));
                    inv.setAccountedValue(new Long(0));

                    ne_marad = 0;
                    tblWork.getItems().add(inv);
                } else {
                    Inventory inv = new Inventory();
                    Inventory cur = tblOperation.getItems().get(i);
                    long ne_bef = Math.round(cur.getNominal().doubleValue());
                    long ne_share = Math.min(ne_marad, ne_bef);
                    inv.setAcquisitionDate(cur.getAcquisitionDate());
                    inv.setAcquisitionValue(cur.getAcquisitionValue());
                    inv.setAcquisitionRateCurrency(cur.getAcquisitionRateCurrency());
                    inv.setAcquisitionValueCurrency(cur.getAcquisitionValueCurrency());
                    inv.setMarketValue(cur.getMarketValue());
                    inv.setNominal(cur.getNominal());
                    inv.setPurchaseId(cur.getPurchaseId());
                    inv.setQuantity(cur.getQuantity());
                    inv.setAccumulatedInterestAccountedPrice(new Long(0));
                    inv.setDerecogniseCurrencyRateDelta(cur.getDerecogniseCurrencyRateDelta());
                    inv.setDerecogniseDividend(cur.getDerecogniseDividend());
                    inv.setDerecogniseInterest(cur.getDerecogniseInterest());
                    inv.setDerecogniseRateDelta(cur.getDerecogniseRateDelta());
                    inv.setDerecognisedCurrencyRateDelta(new Long(0));
                    inv.setDerecognisedDividend(new Long(0));
                    inv.setDerecognisedInterest(Math.round(inv.getDerecogniseInterest().doubleValue() * ne_share / ne_bef));
                    inv.setDerecognisedRateDelta(new Long(0));
                    inv.setDerecogniseInterest(cur.getDerecogniseInterest() - inv.getDerecognisedInterest());
                    inv.setRealisedCurrencyRateDelta(new Long(0));
                    inv.setRealisedDividend(new Long(0));
                    inv.setRealisedInterest(Math.round((double) ne_share / ne_delta * Long.parseLong(tfAccumulatedInterest.getText())));
                    inv.setRealisedRateDelta(new Long(0));
                    inv.setSerial(tfSerial.getText());
                    inv.setAccountedBase((double) ne_share / ne_delta * Long.parseLong(tfNominal.getText()));
                    inv.setAccountedValue(Math.round(Long.parseLong(tfNetRateValue.getText()) * (double) ne_share / ne_delta));

                    tblWork.getItems().add(inv);
                    ne_marad -= ne_share;
                }
            }
        } else if (operationType.equals("osztalékfizetés")) {
            if (!isin.getInstrumentGroup().equals("részvény")) {
                errorLabel.setText("Ezt a műveletet csak részvényeken lehet végrehajtani!");
                return;
            }
            if (tfDividend.getText().isEmpty()) {
                errorLabel.setText("Az osztlékfizetés mértékét kötelező megadni!");
                return;
            }
            if (tfQuantity.getText().isEmpty()) {
                errorLabel.setText("Az osztlékfizetéshez a mennyiséget kötelező megadni!");
                return;
            }
            int db_delta = Integer.parseInt(tfQuantity.getText());
            int db_marad = db_delta;
            int i = 0;
            while (db_marad > 0) {
                if (i == tblOperation.getItems().size()) {
                    // rendkivul alacsony valoszinusegu eset kezelese
                    // osztalekfizetes olyan papirra ami mar nincs bent a leltarban
                
                    Inventory inv = new Inventory();

                    inv.setAcquisitionDate(null);
                    inv.setAcquisitionValue(new Long(0));
                    inv.setAcquisitionRateCurrency(new Float(0));
                    inv.setAcquisitionValueCurrency(new Double(0));
                    inv.setMarketValue(new Long(0));
                    inv.setNominal(new Double(db_marad));
                    inv.setPurchaseId(null);
                    inv.setQuantity(new Integer(0));
                    inv.setAccumulatedInterestAccountedPrice(new Long(0));
                    inv.setDerecognisedCurrencyRateDelta(new Long(0));
                    inv.setDerecognisedDividend(new Long(0));
                    inv.setDerecognisedInterest(new Long(0));
                    inv.setDerecognisedRateDelta(new Long(0));
                    inv.setDerecogniseCurrencyRateDelta(new Long(0));
                    inv.setDerecogniseDividend(new Long(0));
                    inv.setDerecogniseInterest(new Long(0));
                    inv.setDerecogniseRateDelta(new Long(0));
                    inv.setRealisedCurrencyRateDelta(new Long(0));
                    inv.setRealisedDividend(Math.round((double) db_marad / db_delta * Long.parseLong(tfDividend.getText())));
                    inv.setRealisedInterest(new Long(0));
                    inv.setRealisedRateDelta(new Long(0));
                    inv.setSerial(tfSerial.getText());
                    inv.setAccountedBase((double) db_marad / db_delta * Long.parseLong(tfDividend.getText()));
                    inv.setAccountedValue(new Long(0));
                    tblWork.getItems().add(inv);
                    db_marad = 0;
                } else {
                    Inventory inv = new Inventory();
                    Inventory cur = tblOperation.getItems().get(i);
                    int db_bef = cur.getQuantity().intValue();
                    int db_share = Math.min(db_marad, db_bef);
                    inv.setAcquisitionDate(cur.getAcquisitionDate());
                    inv.setAcquisitionValue(cur.getAcquisitionValue());
                    inv.setAcquisitionRateCurrency(cur.getAcquisitionRateCurrency());
                    inv.setAcquisitionValueCurrency(cur.getAcquisitionValueCurrency());
                    inv.setMarketValue(cur.getMarketValue());
                    inv.setNominal(cur.getNominal());
                    inv.setPurchaseId(cur.getPurchaseId());
                    inv.setQuantity(cur.getQuantity());
                    inv.setAccumulatedInterestAccountedPrice(new Long(0));
                    inv.setDerecogniseCurrencyRateDelta(cur.getDerecogniseCurrencyRateDelta());
                    inv.setDerecogniseDividend(cur.getDerecogniseDividend());
                    inv.setDerecogniseInterest(cur.getDerecogniseInterest());
                    inv.setDerecogniseRateDelta(cur.getDerecogniseRateDelta());
                    inv.setDerecognisedCurrencyRateDelta(new Long(0));
                    inv.setDerecognisedDividend(Math.round(inv.getDerecogniseDividend().doubleValue() * db_share / db_bef));
                    inv.setDerecognisedInterest(new Long(0));
                    inv.setDerecognisedRateDelta(new Long(0));
                    inv.setDerecogniseDividend(cur.getDerecogniseDividend() - inv.getDerecognisedDividend());
                    inv.setRealisedCurrencyRateDelta(new Long(0));
                    inv.setRealisedDividend(Math.round((double) db_share / db_delta * Long.parseLong(tfDividend.getText())));
                    inv.setRealisedInterest(new Long(0));
                    inv.setRealisedRateDelta(new Long(0));
                    inv.setSerial(tfSerial.getText());
                    inv.setAccountedBase((double) db_share / db_delta * Long.parseLong(tfDividend.getText()));
                    inv.setAccountedValue(Math.round(Long.parseLong(tfNetRateValue.getText()) * (double) db_share / db_delta));
                    tblWork.getItems().add(inv);
                    db_marad -= db_share;
                }

            }
        } else if (operationType.equals("tőketörlesztés")) {
            if (tfNominal.getText().isEmpty()) {
                errorLabel.setText("A névértéket kötelező kitölteni!");
                return;
            }
            long ne_delta = Long.parseLong(tfNominal.getText());
            long ne_marad = ne_delta;
            int i = 0;
            while (ne_marad > 0) {
                Inventory cur = tblOperation.getItems().get(i);
                Inventory inv = new Inventory();
                long ne_bef = Math.round(cur.getNominal());
                long ne_share = Math.min(ne_bef, ne_marad);
                inv.setAcquisitionDate(cur.getAcquisitionDate());
                inv.setAcquisitionValue(Math.round(cur.getAcquisitionValue() * (1.0 - ne_share / ne_bef)));
                inv.setAcquisitionRateCurrency(cur.getAcquisitionRateCurrency());
                inv.setAcquisitionValueCurrency(cur.getAcquisitionValueCurrency() * (1.0 - ne_share / ne_bef));
                inv.setMarketValue(Math.round(cur.getMarketValue() * (1.0 - ne_share / ne_bef)));
                inv.setNominal(cur.getNominal() * (1.0 - ne_share / ne_bef));
                inv.setPurchaseId(cur.getPurchaseId());
                inv.setQuantity(cur.getQuantity());
                inv.setAccumulatedInterestAccountedPrice(new Long(0));
                inv.setDerecogniseCurrencyRateDelta(cur.getDerecogniseCurrencyRateDelta());
                inv.setDerecogniseDividend(cur.getDerecogniseDividend());
                inv.setDerecogniseInterest(cur.getDerecogniseInterest());
                inv.setDerecogniseRateDelta(cur.getDerecogniseRateDelta());
                inv.setDerecognisedCurrencyRateDelta(new Long(0));
                inv.setDerecognisedDividend(new Long(0));
                inv.setDerecognisedInterest(new Long(0));
                inv.setDerecognisedRateDelta(new Long(0));
                inv.setDerecogniseDividend(new Long(0));
                inv.setRealisedCurrencyRateDelta(new Long(0));
                inv.setRealisedDividend(new Long(0));
                inv.setRealisedInterest(new Long(0));
                inv.setRealisedRateDelta(new Long(0));
                inv.setSerial(tfSerial.getText());
                inv.setAccountedBase((double) ne_share / ne_delta * Long.parseLong(tfNominal.getText()));
                inv.setAccountedValue(Math.round(Long.parseLong(tfNetRateValue.getText()) * (double) ne_share / ne_delta));
                tblWork.getItems().add(inv);
                ne_marad -= ne_share;
            }
        }
        // szamitasi eredmenyek megjelenitese
        tblOperation.getItems().addAll(tblWork.getItems());

        btnPreview.setDisable(true);
    }

    // muveletek betoltese fajlbol
    @FXML
    private void handleImportButtonAction(ActionEvent event)
    {
        // fajlkezelo letrehozza a muveletek listajat
        ArrayList<Operation> ops = XLSHandler.importOperation();
        // a lista minden elemere
        for (Operation op: ops)
        {
            // felulet beallitasa
            cbType.getSelectionModel().select(op.getType());
            cbPortfolio.getSelectionModel().select(op.getPort());
            tfISIN.setText(op.getIsin().getIsin());
            tfSerial.setText(op.getOperationId());
            tfBindingDate.setText(op.getBindingDate().toString());
            tfFulfillmentDate.setText(op.getFulfillmentDate().toString());
            tfExecutionDate.setText(op.getExecutionDate().toString());
            tfQuantity.setText(Integer.toString(op.getQuantity()));
            tfNominal.setText(Double.toString(op.getNominal()));
            tfNetRateValue.setText(Long.toString(op.getNetRateValue()));
            tfDividend.setText(Long.toString(op.getDividend()));
            tfAccumulatedInterest.setText(Long.toString(op.getAccumulatedInterest()));
            tfYield.setText(Long.toString(op.getYield()));
            tfGrossPrice.setText(Long.toString(op.getGrossPrice()));
            tfCommissionHUF.setText(Long.toString(op.getCommissionHUF()));
            tfCapitalValue.setText(Long.toString(op.getCapitalValue()));
            tfBindingRateCurrency.setText(Float.toString(op.getBindingRate()));
            tfFulfillmentRateCurrency.setText(Float.toString(op.getFulfillmentRate()));
            tfExecutionRateCurrency.setText(Float.toString(op.getExecutionRate()));
            tfNetRateCurrency.setText(Double.toString(op.getCurrencyRate()));
            tfNetRatePercent.setText(Float.toString(op.getNetRatePercent()));
            tfComment.setText(op.getNote());
            tfAccumulatedInterestPercent.setText(Float.toString(op.getAccumulatedInterestPercent()));
            tfYieldPercent.setText(Float.toString(op.getYieldPercent()));
            tfCommissionCurrency.setText(Double.toString(op.getCommissionCurrency()));
            tfGrossPriceCurrency.setText(Double.toString(op.getGrossPriceCurrency()));
            // haromlepcsos rogzites
            handleISINButtonAction(new ActionEvent());
            handlePreviewButtonAction(new ActionEvent());
            handleRecordButtonAction(new ActionEvent());
        }
    }
    
    // muveletek rogzitese az adatbazisban
    private void registerTransaction(Operation op, ObservableList<Inventory> inventories) {
        Director director = Director.getInstance();
        AccessInfo ai = director.getAccessInfo();
        try {
            Connection con = DriverManager.getConnection("jdbc:sqlserver://" + ai.getIPAddress() + ":" + ai.getPort() + ";databaseName=" + ai.getDBName(), ai.getUser(), ai.getPass());
            int i = 0;
            for (Inventory inv : inventories) {
                tblOperation.getItems().removeAll(tblWork.getItems());
                i++;
                
                // a leltarak rogzitese mindig azonos
                String invInsert = "INSERT INTO leltar VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                PreparedStatement invStmt = con.prepareStatement(invInsert);
                invStmt.setNString(1, inv.getPurchaseId());
                invStmt.setInt(2, ai.getTrusteeSign());
                invStmt.setInt(3, isin.getId());
                invStmt.setInt(4, portIds.get(cbPortfolio.getSelectionModel().getSelectedIndex()));
                invStmt.setDate(5, Date.valueOf(inv.getAcquisitionDate()));
                invStmt.setInt(6, inv.getQuantity());
                invStmt.setDouble(7, inv.getNominal());
                invStmt.setLong(8, inv.getAcquisitionValue());
                invStmt.setLong(9, inv.getMarketValue());
                invStmt.setLong(10, inv.getDerecogniseInterest());
                invStmt.setLong(11, inv.getDerecogniseDividend());
                invStmt.setLong(12, inv.getDerecogniseRateDelta());
                invStmt.setLong(13, inv.getDerecogniseCurrencyRateDelta());
                invStmt.setDouble(14, inv.getAcquisitionValueCurrency());
                invStmt.setFloat(15, inv.getAcquisitionRateCurrency());
                invStmt.setString(16, inv.getSerial());
                invStmt.executeUpdate();

                // a muveletek rogzitese elter tranzakciotipusonkent
                String tranInsert = "INSERT INTO muvelet VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                PreparedStatement tranStmt = con.prepareStatement(tranInsert);
                tranStmt.setInt(1, isin.getId());
                tranStmt.setInt(2, portIds.get(cbPortfolio.getSelectionModel().getSelectedIndex()));
                tranStmt.setInt(3, typeIds.get(cbType.getSelectionModel().getSelectedIndex()));
                tranStmt.setNString(4, op.getOperationId());
                tranStmt.setNString(5, inv.getPurchaseId());
                tranStmt.setFloat(10, op.getNetRatePercent());
                tranStmt.setFloat(12, op.getAccumulatedInterestPercent());
                tranStmt.setFloat(14, op.getYieldPercent());
                tranStmt.setDate(20, op.getBindingDate());
                tranStmt.setDate(21, op.getExecutionDate());
                tranStmt.setDate(22, op.getFulfillmentDate());
                tranStmt.setFloat(24, op.getBindingRate());
                tranStmt.setFloat(25, op.getExecutionRate());
                tranStmt.setFloat(26, op.getFulfillmentRate());
                tranStmt.setLong(30, op.getAccountedCommissionRateDelta());
                tranStmt.setLong(31, op.getAccountedPriceRateDelta());
                tranStmt.setLong(32, inv.getRealisedInterest());
                tranStmt.setLong(33, inv.getRealisedDividend());
                tranStmt.setLong(34, inv.getRealisedRateDelta());
                tranStmt.setLong(35, inv.getRealisedCurrencyRateDelta());
                tranStmt.setLong(36, inv.getDerecognisedInterest());
                tranStmt.setLong(37, inv.getDerecognisedDividend());
                tranStmt.setLong(38, inv.getDerecognisedRateDelta());
                tranStmt.setLong(39, inv.getDerecognisedCurrencyRateDelta());
                if (cbType.getSelectionModel().getSelectedItem().toString().equals("vásárlás")) {
                    tranStmt.setInt(6, op.getQuantity());
                    tranStmt.setDouble(7, op.getNominal());
                    tranStmt.setDouble(8, op.getCurrencyRate());
                    tranStmt.setLong(9, op.getNetRateValue());
                    tranStmt.setLong(11, op.getAccumulatedInterest());
                    tranStmt.setLong(13, op.getYield());
                    tranStmt.setLong(15, op.getGrossPrice());
                    tranStmt.setLong(16, op.getCommissionHUF());
                    tranStmt.setLong(17, op.getCapitalValue());
                    tranStmt.setLong(18, inv.getAccumulatedInterestAccountedPrice());
                    tranStmt.setLong(19, inv.getAccountedValue());
                    tranStmt.setLong(23, op.getDividend());
                    tranStmt.setDouble(27, op.getGrossPriceCurrency());
                    tranStmt.setDouble(28, op.getCommissionCurrency());
                    tranStmt.setNString(29, op.getNote());
                } else {
                    tranStmt.setLong(18, 0);
                    if (i > tblOperation.getItems().size()) {
                        tranStmt.setInt(6, 0);
                        tranStmt.setDouble(7, 0);
                        tranStmt.setDouble(8, inv.getAccountedValue()*op.getFulfillmentRate());
                        tranStmt.setLong(9, inv.getAccountedValue());
                        if (cbType.getSelectionModel().getSelectedItem().toString().equals("kamatfizetés"))
                            tranStmt.setLong(11, op.getAccumulatedInterest());
                        else
                            tranStmt.setLong(11, 0);
                        tranStmt.setLong(13, op.getYield());
                        tranStmt.setLong(15, 0);
                        tranStmt.setLong(16, 0);
                        tranStmt.setLong(17, 0);
                        tranStmt.setLong(19, inv.getAccountedValue());
                        if (cbType.getSelectionModel().getSelectedItem().toString().equals("osztalékfizetés"))
                            tranStmt.setLong(23, op.getDividend());
                        else
                            tranStmt.setLong(23, 0);
                        tranStmt.setDouble(27, 0);
                        tranStmt.setDouble(28, 0);
                        tranStmt.setNString(29, "technikai rekord - " + op.getNote());
                        break;
                    }
                    else
                    {
                        tranStmt.setNString(29, op.getNote());
                        if (lBase.getText().equals("mennyiség")){
                            tranStmt.setInt(6, inv.getAccountedBase().intValue());
                            tranStmt.setDouble(7, op.getNominal()*inv.getAccountedBase()/op.getQuantity());
                            tranStmt.setDouble(8, inv.getAccountedValue()*op.getFulfillmentRate()*inv.getAccountedBase()/op.getQuantity());
                            tranStmt.setLong(9, Math.round(op.getNetRateValue()*inv.getAccountedBase()/op.getQuantity()));
                            tranStmt.setLong(11, Math.round(op.getAccumulatedInterest()*inv.getAccountedBase()/op.getQuantity()));
                            tranStmt.setLong(13, Math.round(op.getYield()*inv.getAccountedBase()/op.getQuantity()));
                            tranStmt.setLong(15, Math.round(op.getGrossPrice()*inv.getAccountedBase()/op.getQuantity()));
                            tranStmt.setLong(16,Math.round(op.getCommissionHUF()*inv.getAccountedBase()/op.getQuantity()));
                            tranStmt.setLong(17,Math.round(op.getCapitalValue()*inv.getAccountedBase()/op.getQuantity()));
                            tranStmt.setLong(19, inv.getAccountedValue());
                            tranStmt.setLong(23, Math.round(op.getDividend()*inv.getAccountedBase()/op.getQuantity()));
                            tranStmt.setDouble(27, op.getGrossPriceCurrency()*inv.getAccountedBase()/op.getQuantity());
                            tranStmt.setDouble(28, op.getCommissionCurrency()*inv.getAccountedBase()/op.getQuantity());
                        }
                        else{
                            tranStmt.setInt(6, (int)Math.round(op.getQuantity()*inv.getAccountedBase()/op.getNominal()));
                            tranStmt.setDouble(7, inv.getAccountedBase());
                            tranStmt.setDouble(8, inv.getAccountedValue()*op.getFulfillmentRate()*inv.getAccountedBase()/op.getNominal());
                            tranStmt.setLong(9, Math.round(op.getNetRateValue()*inv.getAccountedBase()/op.getNominal()));
                            tranStmt.setLong(11, Math.round(op.getAccumulatedInterest()*inv.getAccountedBase()/op.getNominal()));
                            tranStmt.setLong(13, Math.round(op.getYield()*inv.getAccountedBase()/op.getNominal()));
                            tranStmt.setLong(15, Math.round(op.getGrossPrice()*inv.getAccountedBase()/op.getNominal()));
                            tranStmt.setLong(16,Math.round(op.getCommissionHUF()*inv.getAccountedBase()/op.getNominal()));
                            tranStmt.setLong(17,Math.round(op.getCapitalValue()*inv.getAccountedBase()/op.getNominal()));
                            tranStmt.setLong(19, inv.getAccountedValue());
                            tranStmt.setLong(23, Math.round(op.getDividend()*inv.getAccountedBase()/op.getNominal()));
                            tranStmt.setDouble(27, op.getGrossPriceCurrency()*inv.getAccountedBase()/op.getNominal());
                            tranStmt.setDouble(28, op.getCommissionCurrency()*inv.getAccountedBase()/op.getNominal());
                        }
                    }
                }
                tranStmt.executeUpdate();
                
                String trusteeInsert = "INSERT INTO muv_vk VALUES((SELECT TOP 1 id FROM muvelet WHERE id_muvelet = ?),?,'2011-01-01','2099-12-31')";
                PreparedStatement trusteeStmt = con.prepareStatement(trusteeInsert);
                trusteeStmt.setNString(1, op.getOperationId());
                trusteeStmt.setInt(2, ai.getTrusteeId());
                trusteeStmt.executeUpdate();
            }   
            con.close();
        } catch (SQLException sqle) {
            errorLabel.setText(sqle.getMessage());
            sqle.printStackTrace();
        }
    }

    // kilepes visszalep a fomenube
    @FXML
    private void handleEscapeButtonAction(ActionEvent event) {
        Director director = Director.getInstance();
        director.initializeMainMenu();
    }

    // inicializalas
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        Director director = Director.getInstance();
        AccessInfo ai = director.getAccessInfo();
        try {
            Connection con = DriverManager.getConnection("jdbc:sqlserver://" + ai.getIPAddress() + ":" + ai.getPort() + ";databaseName=" + ai.getDBName(), ai.getUser(), ai.getPass());

            // valaszto vezerlok es azonosito listak feltoltese
            String typeQuery = "SELECT * FROM tranzakcio";
            PreparedStatement stmt = con.prepareStatement(typeQuery);
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                int typeId = rs.getInt(1);
                String tran = rs.getNString(2);
                typeIds.add(new Integer(typeId));
                cbType.getItems().add(tran);
            }
            cbType.getSelectionModel().select(0);

            String portQuery = "SELECT * FROM portfolio";
            PreparedStatement stmt2 = con.prepareStatement(portQuery);
            ResultSet rs2 = stmt2.executeQuery();
            while (rs2.next()) {
                Integer port_id = new Integer(rs2.getInt(1));
                String port = rs2.getNString(2);
                portIds.add(port_id);
                cbPortfolio.getItems().add(port);
            }
            cbPortfolio.getSelectionModel().select(0);

            // kapcsolat zarasa
            con.close();

        } catch (SQLException sqle) {
            errorLabel.setText(sqle.getMessage());
        }

        // oszlopok definicioja
        TableColumn<Inventory, Long> col1 = new TableColumn<Inventory, Long>("Elszámolt mennyiség / névérték");
        col1.setCellValueFactory(new PropertyValueFactory("accountedBase"));

        TableColumn<Inventory, String> col2 = new TableColumn<Inventory, String>("Vételi ID");
        col2.setCellValueFactory(new PropertyValueFactory("purchaseId"));

        TableColumn<Inventory, String> col3 = new TableColumn<Inventory, String>("Beszerzés dátuma");
        col3.setCellValueFactory(new PropertyValueFactory("acquisitionDate"));

        TableColumn<Inventory, Integer> col4 = new TableColumn<Inventory, Integer>("Mennyiség");
        col4.setCellValueFactory(new PropertyValueFactory("quantity"));

        TableColumn<Inventory, Double> col5 = new TableColumn<Inventory, Double>("Névérték");
        col5.setCellValueFactory(new PropertyValueFactory("nominal"));

        TableColumn<Inventory, Long> col6 = new TableColumn<Inventory, Long>("Beszerzési érték");
        col6.setCellValueFactory(new PropertyValueFactory("acquisitionValue"));

        TableColumn<Inventory, Long> col7 = new TableColumn<Inventory, Long>("Piaci érték");
        col7.setCellValueFactory(new PropertyValueFactory("marketValue"));

        TableColumn<Inventory, Long> col8 = new TableColumn<Inventory, Long>("ÉK - kamat");
        col8.setCellValueFactory(new PropertyValueFactory("derecogniseInterest"));

        TableColumn<Inventory, Long> col9 = new TableColumn<Inventory, Long>("ÉK - osztalék");
        col9.setCellValueFactory(new PropertyValueFactory("derecogniseDividend"));

        TableColumn<Inventory, Long> col10 = new TableColumn<Inventory, Long>("ÉK - egyéb piaci");
        col10.setCellValueFactory(new PropertyValueFactory("derecogniseRateDelta"));

        TableColumn<Inventory, Long> col11 = new TableColumn<Inventory, Long>("ÉK - deviza árfolyam-különbözet");
        col11.setCellValueFactory(new PropertyValueFactory("derecogniseCurrencyRateDelta"));

        TableColumn<Inventory, String> col12 = new TableColumn<Inventory, String>("Ügyletszám");
        col12.setCellValueFactory(new PropertyValueFactory("serial"));

        TableColumn<Inventory, Long> col13 = new TableColumn<Inventory, Long>("Könyv szerinti érték");
        col13.setCellValueFactory(new PropertyValueFactory("accountedValue"));

        TableColumn<Inventory, Long> col14 = new TableColumn<Inventory, Long>("Vételárban elszámolt felhalmozott kamat");
        col14.setCellValueFactory(new PropertyValueFactory("accumulatedInterestAccountedPrice"));

        TableColumn<Inventory, Long> col15 = new TableColumn<Inventory, Long>("Realizált kamat");
        col15.setCellValueFactory(new PropertyValueFactory("realisedInterest"));

        TableColumn<Inventory, Long> col16 = new TableColumn<Inventory, Long>("Realizált osztalék");
        col16.setCellValueFactory(new PropertyValueFactory("realisedDividend"));

        TableColumn<Inventory, Long> col17 = new TableColumn<Inventory, Long>("Realizált egyéb piaci ráhatás");
        col17.setCellValueFactory(new PropertyValueFactory("realisedRateDelta"));

        TableColumn<Inventory, Long> col18 = new TableColumn<Inventory, Long>("Realizált deviza árfolyam-különbözet");
        col18.setCellValueFactory(new PropertyValueFactory("realisedCurrencyRateDelta"));

        TableColumn<Inventory, Long> col19 = new TableColumn<Inventory, Long>("Kivezetett kamat");
        col19.setCellValueFactory(new PropertyValueFactory("derecognisedInterest"));

        TableColumn<Inventory, Long> col20 = new TableColumn<Inventory, Long>("Kivezetett osztalék");
        col20.setCellValueFactory(new PropertyValueFactory("derecognisedDividend"));

        TableColumn<Inventory, Long> col21 = new TableColumn<Inventory, Long>("Kivezetett egyéb piaci ráhatás");
        col21.setCellValueFactory(new PropertyValueFactory("derecognisedRateDelta"));

        TableColumn<Inventory, Long> col22 = new TableColumn<Inventory, Long>("Kivezetett deviza árfolyam-különbözet");
        col22.setCellValueFactory(new PropertyValueFactory("derecognisedCurrencyRateDelta"));

        // oszlopok hozzarandelese a tablazathoz
        tblOperation.getColumns().addAll(col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, col1, col13, col14, col15, col16, col17, col18, col19, col20, col21, col22);
    }
}
